package pl.edu.agh.gameserv.server;

import pl.edu.agh.gameserv.serverapi.GameHandle;
import pl.edu.agh.gameserv.serverapi.GameNotReadyException;
import pl.edu.agh.gameserv.serverapi.GameStatus;
import pl.edu.agh.gameserv.serverapi.NotMyMoveException;

public class GameHandleImpl implements GameHandle {
	GameContainer gameContainer;
	String userName;
	int userNumber;

	public void setGame(GameContainer game, int userNumber) {
		this.gameContainer = game;
		this.userNumber = userNumber;
	}

	public GameHandleImpl(String userName) {
		this.userName = userName;
	}

	public String getUserName() {
		return userName;
	}

	public String getUserName(int number) {
		// TODO Auto-generated method stub
		return gameContainer.getUserName(number);
	}

	public int getMyNumber() {
		return userNumber;
	}

	public int getUserCount() {
		return gameContainer.getUserCount();
	}

	public GameStatus getStatus() {

		if (gameContainer == null)
			return GameStatus.WaitingForOtherPlayers;
		if (gameContainer.isFinished())
			return GameStatus.Finished;
		if (gameContainer.nextMove() == getMyNumber())
			return GameStatus.ReadyForMove;
		else
			return GameStatus.WaitingForMove;

	}

	public void move(String move) throws GameNotReadyException, NotMyMoveException, pl.edu.agh.gameserv.serverapi.IllegalMoveException {
		gameContainer.makeMove(this, move);
	}

	public String getScore() {
		return gameContainer.getScore();
	}

	public String[][] getSituation() {
		return gameContainer.getSituation();
	}

	public int getNextUser() {
		return gameContainer.nextMove();
	}

}
